from django.db import models
from user.models import User
from software.models import SoftwareVersion, Software


class SoftwareQuestion(models.Model):
    QUSETIONSTATE = (
        (0, u'未处理'),
        (1, u'已处理'),
        (2, u'已归档'),
    )
    QUSETIONTYPE = (
        (u'用户使用问题', u'用户使用问题'),
        (u'用户部署问题', u'用户部署问题'),
    )
    softwareVersion = models.ForeignKey(
        SoftwareVersion,
        verbose_name=u"软件",
        on_delete=models.CASCADE,
        related_name='softwareVersion_question',
        null=True
    )
    # software = models.ForeignKey(
    #     Software,
    #     verbose_name=u"软件",
    #     null=True,
    #     on_delete=models.CASCADE,
    #     related_name='softwarequestion_question',
    # )
    questionState = models.CharField(
        verbose_name=u'新增问题处理情况',
        choices=QUSETIONSTATE,
        max_length=20,
        default=u'0',
    )
    questionType = models.CharField(
        choices=QUSETIONTYPE,
        max_length=50,
        default=u'',
        verbose_name=u"问题类型",
    )
    title = models.CharField(
        verbose_name=u'问题标题',
        max_length=50,
        default=u'',
    )
    questionContent = models.CharField(
        verbose_name=u'问题内容',
        max_length=2000,
        default=u'',
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"提出者",
        on_delete=models.CASCADE,
        related_name='software_raiser',
        null=True,
    )
    raiseTime = models.DateTimeField(
        verbose_name=u"提出时间",
        auto_now_add=True,
    )
    ishandle = models.BooleanField(
        verbose_name=u'是否处理',
        default=False,
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.createTime

    class Meta:
        ordering = ('createTime',)


class QuestionHandle(models.Model):
    question = models.ForeignKey(
        SoftwareQuestion,
        verbose_name=u"软件问题",
        on_delete=models.CASCADE,
        related_name='question_handle',
    )
    user = models.ForeignKey(
        User,
        verbose_name=u"处理者",
        on_delete=models.CASCADE,
        related_name='user_questionHandle',
    )
    handleContent = models.CharField(
        verbose_name=u'回复内容',
        max_length=2000,
        default=u'',
    )
    handleTime = models.DateTimeField(
        verbose_name=u"回复时间",
        auto_now_add=True,
    )
    createTime = models.DateTimeField(
        auto_now_add=True,
        verbose_name=u"创建时间",
    )
    isActive = models.BooleanField(
        verbose_name=u'是否活跃',
        default=True,
    )

    def __unicode__(self):
        return self.createTime

    class Meta:
        ordering = ('createTime',)
